﻿using System;

namespace _1534_count_good_triplets
{
    class Program
    {
        static void Main (string[] args)
        {
            int[] arr = new int[] { 1, 1, 2, 2, 3};
            Console.WriteLine (CountGoodTriplets (arr, 0, 0, 1));
        }

        public static int CountGoodTriplets (int[] arr, int a, int b, int c)
        {
            int count = 0;

            for (int i = 0;i < arr.Length-2;i++)
            {
                for (int j = i + 1;j < arr.Length-1;j++)
                {
                    if (Math.Abs (arr[i] - arr[j]) <= a) {
                        for (int k = j + 1;k < arr.Length;k++)
                        {
                            if (Math.Abs (arr[j] - arr[k]) <= b && Math.Abs (arr[i] - arr[k]) <= c)
                                count++;
                        }
                    }
                }
            }

            return count;
        }
    }
}
